package com.yuwenxin.service.impl;

import com.yuwenxin.bean.User;
import com.yuwenxin.dao.UserDao;
import com.yuwenxin.dao.impl.UserDaoImpl;
import com.yuwenxin.service.UserService;

public class UserServiceImpl implements UserService {
    private UserDao dao = new UserDaoImpl();
    @Override
    public User login(User user) throws Exception {
        return findUserByName(user.getName());
//        if (!user_.getPassword().equals(user.getPassword())){
//            return null;
//        }else {
//            return user_;
//        }

    }

    @Override
    public User register(User user) throws Exception {
        User user_ = (User) dao.findByName(user.getName());
        if (user_ == null){
            int row = dao.insert(user);
            System.out.println("成功插入" + row + "条数据...");
            return user;
        }
        return user_;
    }

    @Override
    public int changePassword(User user) throws Exception {
        int row = dao.update(user);
        System.out.println("成功修改" + row + "条数据...");
        return row;
    }

    @Override
    public int userUpdate(User user) throws Exception {
        int n = dao.update(user);
        System.out.println("修改了" + n + "条数据...");
        return n;
    }

    @Override
    public User forgetPassword(User user) {
        return null;
    }

    @Override
    public User addFriend(User user) {
        return null;
    }

    @Override
    public User headPhotoUpload(User user) {
        return null;
    }

    @Override
    public User findUserByName(String name) throws Exception {
        return (User) dao.findByName(name);
    }
}
